package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.vo.PStoreProductCateVo;
import com.ruoyi.system.domain.bo.PStoreProductCateBo;
import com.ruoyi.system.service.IPStoreProductCateService;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiOperation;

/**
 * 商品分类辅助Controller
 *
 * @author ruoyi
 * @date 2022-08-01
 */
@Validated
@Api(value = "商品分类辅助控制器", tags = {"商品分类辅助管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/storeProductCate")
public class PStoreProductCateController extends BaseController {

    private final IPStoreProductCateService iPStoreProductCateService;

    /**
     * 查询商品分类辅助列表
     */
    @ApiOperation("查询商品分类辅助列表")
    @SaCheckPermission("system:storeProductCate:list")
    @GetMapping("/list")
    public TableDataInfo<PStoreProductCateVo> list(PStoreProductCateBo bo, PageQuery pageQuery) {
        return iPStoreProductCateService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出商品分类辅助列表
     */
    @ApiOperation("导出商品分类辅助列表")
    @SaCheckPermission("system:storeProductCate:export")
    @Log(title = "商品分类辅助", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(PStoreProductCateBo bo, HttpServletResponse response) {
        List<PStoreProductCateVo> list = iPStoreProductCateService.queryList(bo);
        ExcelUtil.exportExcel(list, "商品分类辅助", PStoreProductCateVo.class, response);
    }

    /**
     * 获取商品分类辅助详细信息
     */
    @ApiOperation("获取商品分类辅助详细信息")
    @SaCheckPermission("system:storeProductCate:query")
    @GetMapping("/{id}")
    public R<PStoreProductCateVo> getInfo(@ApiParam("主键")
                                     @NotNull(message = "主键不能为空")
                                     @PathVariable("id") Long id) {
        return R.ok(iPStoreProductCateService.queryById(id));
    }

    /**
     * 新增商品分类辅助
     */
    @ApiOperation("新增商品分类辅助")
    @SaCheckPermission("system:storeProductCate:add")
    @Log(title = "商品分类辅助", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody PStoreProductCateBo bo) {
        return toAjax(iPStoreProductCateService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改商品分类辅助
     */
    @ApiOperation("修改商品分类辅助")
    @SaCheckPermission("system:storeProductCate:edit")
    @Log(title = "商品分类辅助", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody PStoreProductCateBo bo) {
        return toAjax(iPStoreProductCateService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除商品分类辅助
     */
    @ApiOperation("删除商品分类辅助")
    @SaCheckPermission("system:storeProductCate:remove")
    @Log(title = "商品分类辅助", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@ApiParam("主键串")
                                       @NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iPStoreProductCateService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
